//
//  TSToolBarTextField.m
//  chart
//
//  Created by xu on 15/8/2.
//  Copyright (c) 2015年 xu. All rights reserved.
//

#import "TSToolBarTextField.h"
#import "TSMutipleCheckTableViewController.h"

@implementation TSToolBarTextField{
    UIToolbar *inputAccessoryView;
}

@synthesize notShowKeyboard,section;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        [self setFont:FONT(12.f)];
    }
    
    return self;
}

- (void)drawRect:(CGRect)rect
{

}

#pragma mark - inputAccessoryView with toolbar
- (BOOL)canBecomeFirstResponder {
    if (notShowKeyboard) {
        [[NSNotificationCenter defaultCenter] postNotificationName:TSNotification_PresentViewController object:@(self.toolBarTextFieldType) userInfo:@{@"section":[NSString stringWithFormat: @"%d", section]}];
        
        return NO;
    }
    
    return YES;
}

- (void)done:(id)sender {
    [super resignFirstResponder];
    
    [self resignFirstResponder];
}

- (UIView *)inputAccessoryView {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return nil;
    } else {
        if (!inputAccessoryView) {
            inputAccessoryView = [[UIToolbar alloc] init];
            inputAccessoryView.barStyle = UIBarStyleBlackTranslucent;
            inputAccessoryView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            [inputAccessoryView sizeToFit];
            CGRect frame = inputAccessoryView.frame;
            frame.size.height = 30.0f;
            inputAccessoryView.frame = frame;
            
            UIBarButtonItem *doneBtn =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
            UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
            
            NSArray *array = [NSArray arrayWithObjects:flexibleSpaceLeft, doneBtn, nil];
            [inputAccessoryView setItems:array];
        }
        return inputAccessoryView;
    }
}



@end
